const eventsFunc = () => {

}

// 处理派发事件
eventsFunc.prototype.processEvent = (eventType, EventList, id, _that) => {
  EventList.map((item, index) => {
    if (item.eventType == eventType) {
      this.emitter.emit(item.custom, { item, id, _that })
    }
    return null;
  })
}

// 跳转详情，加购，自定义事件
eventsFunc.prototype.onTapEvent = (params) => {
  const { item, id, _that } = params
  this.trackFun(id);
  switch (item.details) {
    case "goDetails":
      this.goTargetUrlFn(item, _that);
      break;
    case "addBuy":
      this.addBuyFn(item, _that)
      break;
    case "custom":
      this.customFn(item, _that)
      break;
    default: null
  }
}

// 跳转详情
eventsFunc.prototype.goTargetUrlFn = (params, _that) => {
  // console.log('==========goTargetUrlFn==========', params);
  const { href } = params;
  // console.log(href)
  if (href.includes('http')) {
    my.call("navigateToOutside", {
      url: href
    })
  } else {
    my.navigateTo({
      url: href
    })
  }
}
// 加购
eventsFunc.prototype.addBuyFn = (params, _that) => {
  // console.log(_that,'==========addCart==========', params);

  const { addBuyId } = params;
  // if (!isAddBuy) {
  //   isAddBuy = true;
  my.tb.showSku({
    itemId: addBuyId,
    complete: result => {
      // isAddBuy = false;
    }
  })
}
// 发送自定义事件
eventsFunc.prototype.customFn = (params, _that) => {
  // console.log('----------customFn---------', params)
  const { custom, customData, href } = params;
  this.emitter.emit(custom, customData)
}

eventsFunc.prototype.trackFun = (data) => {
  // var info = {
  //   version: "v2",
  //   projectCode: '申请到的pid',
  //   timestamp: new Date().getTime().toString(),
  //   province: "",
  //   city: "",
  //   customType: data,
  //   origin: "taobao",
  //   userId: globalData.username,
  //   type: null
  // }
  // console.log('info',info)
  // queryRequest(info);
}

exports.eventsFunc = eventsFunc;